package com.huanying.framework.payment;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.huanying.framework.BaseController;
import com.huanying.framework.PageBean;
import com.huanying.framework.user.User;
import com.huanying.framework.user.UserController;
import com.huanying.framework.user.UserService;
@Controller
public class PaymentController extends BaseController{
	@Autowired
	private PaymentService paymentService;
	private UserService userService;
	
	private static Logger logger = Logger.getLogger(PaymentController.class);
    //显示全部交易记录
	@RequestMapping(value = "/show_add_trade_money.do")
	public String show_TradeMoneyInfo(String user_name, String userobject_name,String transactiontime,String create_time,String type,String direction,String amount,String bankType,String status,
			String page_num, Model model) throws Exception {
		
		PageBean pageBean = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("user_name", user_name);
		map.put("userobject_name", userobject_name);
		map.put("transactiontime", transactiontime);
		map.put("create_time", create_time);
		map.put("type", type);		
		map.put("direction", direction);
		map.put("amount", amount);
		map.put("bankType", bankType);
		map.put("status", status);

		if (page_num == null) {
			page_num = "1";
		}

	    //PageBean pageBean = paymentService.searchMoneyRecords(map, 3, Integer.valueOf(page_num));
		try {
		     pageBean = paymentService.searchMoneyRecords(map, super.getPageSize(), Integer.valueOf(page_num));
		     logger.info("查询交易成功");
		} catch (NumberFormatException e) {
			logger.error("查询交易失败", e);
		} catch (Exception e) {
			logger.error("查询交易失败", e);
		}
		model.addAttribute("trades_money", pageBean.getList());
		model.addAttribute("page",pageBean);
		//model.addAttribute("name", name);
		return "trade/add_trade";
	}

	@RequestMapping(value = "/getTradeMoneyRecordIn.do", method = RequestMethod.GET)
	public String getTradeMoneyRecordIn(String id,String page_num, Model model) throws Exception {
		PageBean pageBean = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("user_id", id);

		if (page_num == null) {
			page_num = "1";
		}

	    //PageBean pageBean = paymentService.searchMoneyRecords(map, 3, Integer.valueOf(page_num));
		try {
		       pageBean = paymentService.searchMoneyRecordsQueryIn(map, super.getPageSize(), Integer.valueOf(page_num));
		     logger.info("查询交易成功");
		} catch (NumberFormatException e) {
			logger.error("查询交易失败", e);
		} catch (Exception e) {
			logger.error("查询交易失败", e);
		}
		model.addAttribute("trades_money", pageBean.getList());
		model.addAttribute("page",pageBean);
		//model.addAttribute("name", name);
		return "trade/tradeIn_detail";
	}
	@RequestMapping(value = "/getTradeMoneyRecordOut.do", method = RequestMethod.GET)
	public String getTradeMoneyRecordOut(String id,String page_num, Model model) throws Exception {
		PageBean pageBean = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("user_id", id);

		if (page_num == null) {
			page_num = "1";
		}

		try {
		      pageBean = paymentService.searchMoneyRecordsQueryOut(map, super.getPageSize(), Integer.valueOf(page_num));
		     logger.info("查询交易成功");
		} catch (NumberFormatException e) {
			logger.error("查询交易失败", e);
		} catch (Exception e) {
			logger.error("查询交易失败", e);
		}
		model.addAttribute("trades_money", pageBean.getList());
		model.addAttribute("page",pageBean);
		//model.addAttribute("name", name);
		return "trade/trade_detail";
	}
}
